var itema = [
	{id : 0,code : "1",text : "启用"},
    {id : 1,code : "9",text : "不启用"},
];
itema.map((item,index)=>{
	itema[index] = {boxLabel : item.text ,name :  "statuz",inputValue:item.code};
})
itema[0].checked = true;

var edit_form_panel = Ext.create("Ext.form.Panel", {
	url: "/fk-acti/delegate/edit",
	buttonAlign: "center",
	bodyStyle: "padding: 10px;",
	defaultType : "textfield",
	items: [{
		fieldLabel: "委托业务",
		emptyText: "请选择委托业务",
		allowBlank: false,//是否允许为空
		name: "business",
		width: "100%"
	},
	{
		xtype: "combo",
		fieldLabel: "委托人",
		emptyText: "请选择委托人姓名",
		name: "user",
		allowBlank: false,//是否允许为空
		editable: false,//是否可编辑
		lazyInit: false,//延时初始化下拉列表，默认为true
		triggerAction: 'all',
		valueField: 'value',
		width: "100%",
		store: new Ext.data.ArrayStore({
			fields: ['value', 'text'],
			data: [
					["1", "张三"],
					["0", "李四"]
			],
		}),
	},
	{
		xtype: "combo",
		fieldLabel: "被委托人",
		emptyText: "请选择被委托人姓名",
		name: "userd",
		allowBlank: false,//是否允许为空
		editable: false,//是否可编辑
		lazyInit: false,//延时初始化下拉列表，默认为true
		triggerAction: 'all',
		valueField: 'value',
		width: "100%",
		store: new Ext.data.ArrayStore({
			fields: ['value', 'text'],
			data: [
					["1", "张三"],
					["0", "李四"]
			],
		}),
	},
	{
		xtype: "datefield",
		format: "Y-m-d",
		editable: false,
		allowBlank: false,//是否允许为空
		fieldLabel: "委托开始时间",
		emptyText: "请选择委托开始时间",
		id:"start",
		name: "start",
		width: "100%",
		listeners:{
			select:function(dateField,date){
				var EDate=Ext.getCmp('end').getValue();
				if(EDate != null){
					var flag=date-EDate;
					if(flag>0){
						Ext.getCmp('end').setValue("");
					}				
				}
			}
		}
	},
	{
		xtype: "datefield",
		format: "Y-m-d",
		editable: false,
		allowBlank: false,//是否允许为空
		fieldLabel: "被委结束时间",
		emptyText: "请选择委托结束时间",
		id:"end",
		name: "end",
		width: "100%",
		listeners:{
			select:function(dateField,date){
				var SDate = Ext.getCmp('start').getValue();
				if(SDate != null){
					var flag=date-SDate;
					if(flag<0){
						Ext.getCmp('end').setValue("");
					}	
				}
			}
		}
	},
	{   xtype : 'radiogroup',
	    fieldLabel : '是否启用',
	    items :itema
	},
	{
		xtype: 'textarea',
		labelWidth: 100,
		name:"reason",
		//allowBlank: false,//是否允许为空
		fieldLabel: '委托原因',
		width: 400
	},
	{
		fieldLabel: "kid",
		name: "kid",
		xtype: "hidden",
		width: "100%"	
	}
],
	buttons: [{
		text: "保存",
		formBind: true, // only enabled once the form is valid
		disabled: true,
		handler: function() {
			var form = this.up("form").getForm();
			if (form.isValid()) {
				form.submit({
					waitMsg: "保存中...",
					success: function(form, action) {
						var message = action.result.result;
						Ext.Msg.alert("提示", message);
						edit_form_panel_win.close();
						dataStore.load();
					},
					failure: function(form, action) {
						Ext.Msg.alert("提示", "操作失败！");
					}
				});
			}
		}
	}]
});

var edit_form_panel_win = Ext.create("Ext.Window", {
	title: "委托信息修改",
	closeAction: "hide",
	width: 450,
	items: edit_form_panel
});

function myEdit(kid) {
	Ext.Ajax.request({
		url: "/fk-acti/delegate/edit_form?kid="+kid,
		method: "POST",
		success: function(response) {
			var json = Ext.JSON.decode(response.responseText);
			edit_form_panel.getForm().reset();
			edit_form_panel.getForm().setValues(json.result);
			var start = Ext.util.Format.date(new Date(parseInt(json.result.start)),"Y-m-d")
			var end = Ext.util.Format.date(new Date(parseInt(json.result.end)),"Y-m-d")
			Ext.getCmp("start").setValue(start);
			Ext.getCmp("end").setValue(end);
			edit_form_panel_win.show();
		},
		failure: function(response) {
			Ext.Msg.alert("提示", "操作失败!");
		}
	});
} // #myEdit
